package models

import (
	"gorm.io/gorm"
	"yk/common/mysql"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null;comment:手机号"`
	Nickname string `gorm:"type:varchar(20);not null;comment:昵称"`
	Age      int32  `gorm:"type:int(10);not null;comment:年龄"`
	Sex      int32  `gorm:"type:tinyint(1);default:1;not null;comment:性别:1 男,2 女"`
	Addr     string `gorm:"type:varchar(30);not null;comment:地址"`
}

func (u *User) Reg() error {
	return mysql.Db.Model(User{}).Create(&u).Error
}

func Login(mobile string) (u *User, err error) {
	err = mysql.Db.Model(User{}).Where("mobile = ?", mobile).First(&u).Error
	return
}

func Update(id int32) (u *User, err error) {
	err = mysql.Db.Model(User{}).Update("id = ?", id).Error
	return
}

type SendSms struct {
	gorm.Model
	Mobile string `gorm:"type:char(11);not null;comment:手机号"`
	Code   string `gorm:"type:char(8);not null;comment:验证码"`
}

func (s *SendSms) SendCreate() error {
	return mysql.Db.Model(SendSms{}).Create(&s).Error
}

type UserXy struct {
	gorm.Model
	UserId      int32 `gorm:"type:int(10);not null;comment:用户ID"`
	CreditScore int32 `gorm:"type:int(10);not null;comment:信誉分"`
}

func (u *UserXy) UserXy() error {
	return mysql.Db.Model(UserXy{}).Create(&u).Error
}

type OrderCar struct {
	gorm.Model
	UserId        int32  `gorm:"type:int(10);not null;comment:用户ID"`
	OddNumber     int32  `gorm:"type:int(10);not null;comment:单号"`
	Distance      string `gorm:"type:varchar(20);not null;comment:行程"`
	Time          string `gorm:"type:varchar(10);not null;comment:时间"`
	Price         int32  `gorm:"type:int(10);not null;comment:价格"`
	PaymentMethod int32  `gorm:"type:int(10);not null;default:1;comment:支付方式:1 微信,2 支付宝,3 现金"`
}

func OrderCarList() (o *OrderCar, err error) {
	err = mysql.Db.Model(OrderCar{}).Find(&o).Error
	return
}

type TakeCar struct {
	gorm.Model
	UserId         int32  `gorm:"type:int(10);not null;comment:用户ID"`
	Origin         string `gorm:"type:varchar(20);not null;comment:起始地"`
	Destination    string `gorm:"type:varchar(20);not null;comment:目的地"`
	EstimatedPrice int32  `gorm:"type:int(10);not null;comment:预估价格"`
	Price          int32  `gorm:"type:int(10);not null;comment:价格"`
}

func (t *TakeCar) TakeCreate() error {
	return mysql.Db.Model(TakeCar{}).Create(&t).Error
}

type Driver struct {
	gorm.Model
	Nickname string `gorm:"type:varchar(20);not null;comment:昵称"`
	Age      int32  `gorm:"type:int(10);not null;comment:年龄"`
	Sex      int32  `gorm:"type:tinyint(1);default:1;not null;comment:性别:1 男,2 女"`
	Addr     string `gorm:"type:varchar(30);not null;comment:地址"`
}

type Evaluate struct {
	gorm.Model
	DriverId int32  `gorm:"type:int(10);not null;comment:司机ID"`
	UserId   int32  `gorm:"type:int(10);not null;comment:用户ID"`
	Score    int32  `gorm:"type:tinyint(1);default:5;not null;comment:评分:1 ☆,2 ☆☆,3 ☆☆☆,4 ☆☆☆☆,5 ☆☆☆☆☆"`
	Comment  string `gorm:"type:varchar(30);not null;comment:评论内容"`
}

func (e *Evaluate) EvaCreate() error {
	return mysql.Db.Model(Evaluate{}).Create(&e).Error
}
